<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_company extends Controller_Abstract {
	
	function actionIndex()
	{
		 $this->union_table = company::meta();
		 $this->lists();
	}

	function actionDel() {
	     Syslog::logs("删除预约，ID：".print_r($this->_context->ids,true));
	     $this->union_table = company::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	  	    	  
	}

	function actionAdd() {
		//设置要操作的表单，并设置自动插入方式
		$this->union_table = company::meta ();
		$handle = new helper_autoinsert ( $this->union_table );
		$form = new form_company_add ( url ( $this->_context->controller_name . '/' . $this->_context->action_name ) );
		//这里面会自动将get方式获取的参数传递到表单里面去的
		$result = $handle->add ( $form, 'id', $_GET );
		if ($this->_context->isGET ()) {
			//传递$form值
			$this->_view ['form'] = $result;
			$this->_viewname = '../form/add';
			$form->element('acct_id')->value = $_SESSION['acct']['id'];
		} else {
			//记录日志
			if(!$_POST['id'])	{
				Syslog::logs ( '添加公司,id :' . $handle->form_database_obj->id );
			}else{
				Syslog::logs ( '编辑公司,id :' . $handle->form_database_obj->id );
			}
			if($handle->status=='success')
				$this->_context->forwardUrl = url("company/index");
			return call_user_func_array(array($this,$handle->status),array($result));
		}
	}

	function actionsee(){
		$this->union_table = acctuser::meta();
		$this->lists();
	}

	function actionepeople(){
		$acctuser = acctuser::find('id = ? ', $this->_context->id)->getOne();
		$this->_view['data']=$acctuser;
	}

	function actionsubepeople(){
		$acctuser = acctuser::find('id=?',$this->_context->id)->getOne();
		$acctuser->department = $this->_context->department;
		$acctuser->save();
		$this->success('设置成功');
	}

	function actiondpeople(){
		$id=$this->_context->id;
		$acctuser = acctuser::find('id=?',$id)->getOne();
		$acctuser->company_id = 0;
		$acctuser->department = '';
		$acctuser->save();
		exit(json_encode(array('code' => 1, 'msg' => '操作成功')));
	}


}


